package com.tankgame.its381b;

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;



public class bullet extends Sprite {
	
	//create variables needed for creation and movement of bullet
    private static final int WIDTH = 16;
    private static final int HEIGHT = 16;
    private static final int MULTIPLIER = 4;
    private static double xdelta, ydelta;
    private static int ixdelta, iydelta;


    //bullet is created at X and Y with a firingAngle
    public bullet(int x, int y, double firingAngle) throws IOException {
    	
    	//create bullet with fireballs.png and width height
        super(Image.createImage("/res/fireballs.png"), WIDTH, HEIGHT);
        defineReferencePixel(WIDTH, HEIGHT);
        
        //set position to x,y from creation -5 pixels
        setPosition( x - 5, y - 5 );
        /***
         *  The parametric equation for a circle is
         *  x = cx + r * cos(a)
         *  y = cy + r * sin(a)
         *
         ***/
        //set xdelta and ydelta to a value based on parametric equation and firing angle
        //multiplier is used so we can later change to int and avoid cutting off decimal values
        xdelta = Math.cos(Math.toRadians(firingAngle)) * MULTIPLIER;
        ydelta = Math.sin(Math.toRadians(firingAngle)) * MULTIPLIER;
        
        //change xdelta and ydelta to integer values
        ixdelta = (int)xdelta;
        iydelta = (int)ydelta;
    }

    public void move() {
    	//set sprite image to next frame
        nextFrame();
        //move according to integer values ixdelta,iydelta
        move(ixdelta, iydelta);
    }
}
